#include "runningChart.h"

RunningChart::RunningChart()
{
//    _chart = new PCRChartItem();
//    _chartview = new QChartView();
    _anchor = nullptr;
}


void RunningChart::load(){
//    qDebug() << "加载运行图表";
//    QObject *pRoot = engine->rootObjects().first();

//    QQuickItem *chartItem = pRoot->findChild<QQuickItem *>("RunningChartLine");

//    QQuickWindow* qmlwindow = qobject_cast<QQuickWindow *>(engine->rootObjects().first());
//    QWindow* chartWindow = QWindow::fromWinId(_chartview->winId());

//    chartWindow->setParent(qmlwindow);

//    _chartview->setChart(_chart);
//    _chart->axisX()->setTitleText("循环数(Cycles)");
//    _chart->axisY()->setTitleText("荧光强度(Ru)");

//    QVector<QPointF> pointList;
//    _chart->appendCurve("string1", pointList, "spline");
//    _anchor = new WidgetAnchor(_chartview, chartItem);
//    _anchor->hide();
//    _chartview->setStyleSheet("background: rgba(255,255,255,1);");

}

void RunningChart::show(){
//    if(_anchor)
//        _anchor->show();
}

void RunningChart::hide(){
//    if(_anchor)
//        _anchor->hide();
}

QVariantList RunningChart::getChartData(QString equId, QString accessInfo, QString posInfo, int cycleNum){
    //    qDebug() << "刷新运行曲线图图表" << "设备ID" << equId;
    //    qDebug() << "通道信息:" << accessInfo;
    //    qDebug() << "孔位信息:" << posInfo;


    QVector<QVector<QPointF>> lists;
    QStringList channelList = accessInfo.split(',');

    QVariantList res;
    foreach(QString channel, channelList){
        lists = expPro->getChartInfo(equId, channel, posInfo);

        for(int i = 0; i < lists.size(); i ++){

            QVariantMap curve;
            curve["Color"] = QColor(166, 166, 166);
            // 颜色暂时定义
            if(channel=="FAM"){
                curve["Color"] = QColor(22, 119, 255);
            }if(channel=="VIC"){
                curve["Color"] = QColor(103, 194, 58);
            }if(channel=="ROX"){
                curve["Color"] = QColor(235, 137, 20);
            }if(channel=="CY5"){
                curve["Color"] = QColor(245, 108, 105);
            }
            QVariantList pointList;
            foreach(QPointF point, lists[i]){
                QVariantMap p;
                p["x"] = point.x();
                p["y"] = point.y();
                pointList.push_back(p);
            }
            curve["PointList"] = pointList;

            res.push_back(curve);
        }
    }
    return res;
}

void RunningChart::refresh(QString equId, QString accessInfo, QString posInfo, int cycleNum){


//    qDebug() << "刷新运行曲线图图表" << "设备ID" << equId;
//    qDebug() << "通道信息:" << accessInfo;
//    qDebug() << "孔位信息:" << posInfo;


//    QVector<QVector<QPointF>> lists;
//    QStringList channelList = accessInfo.split(',');

//    _chart->changeCurveState_reg("", PCRChartItem::HIDE);
//    foreach(QString channel, channelList){
//        lists = expPro->getChartInfo(equId, channel, posInfo);

//        for(int i = 0; i < lists.size(); i ++){
//            QVector<QPointF> pointList = lists[i];
//            _chart->appendCurve(channel+QString::number(i), pointList, "spline");
//            _chart->changeCurveState(channel+QString::number(i), PCRChartItem::NORM);
//        }
//    }
//    _chart->updateCurve();
//    if(cycleNum != -1){
//        _chart->updateRangeX(1, cycleNum);
//    }else{
//        _chart->updateRange();
//    }

}
